﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Fluent="clr-namespace:Fluent"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:Converters="clr-namespace:Fluent.Converters" xmlns:internal="clr-namespace:Fluent.Internal"
                    mc:Ignorable="d">
    <ControlTemplate x:Key="RibbonControlTemplate"
                     TargetType="{x:Type Fluent:Ribbon}">
        <Grid x:Name="PART_LayoutRoot"
              Width="Auto"
              Height="Auto">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Fluent:RibbonTitleBar x:Name="PART_RibbonTitleBar"
                                   Height="{Binding Path=(Fluent:RibbonProperties.TitleBarHeight), RelativeSource={RelativeSource Self}}"
                                   Style="{DynamicResource RibbonTitleBarStyle}"
                                   Margin="20,0,113,0"
                                   VerticalAlignment="Top"
                                   IsCollapsed="{TemplateBinding IsCollapsed}">
                <Fluent:RibbonTitleBar.Header>
                    <Grid>
                        <Rectangle x:Name="rectangle"
                                   Fill="{DynamicResource RibbonWindowTitleTextGlowBackground}"
                                   Stroke="{x:Null}"
                                   StrokeThickness="0"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Width="{Binding ActualWidth, ElementName=PART_Title, Mode=Default}"
                                   Height="{Binding ActualHeight, ElementName=PART_Title, Mode=Default}"
                                   RadiusX="2"
                                   RadiusY="2">
                            <Rectangle.Effect>
                                <BlurEffect Radius="10" />
                            </Rectangle.Effect>
                        </Rectangle>
                        <TextBlock x:Name="PART_Title"
                                   Padding="4,0,4,0"
                                   VerticalAlignment="Center"
                                   d:LayoutOverrides="Width"
                                   HorizontalAlignment="Center"
                                   Text="{Binding Path=Title,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
                                   Foreground="Black"
                                   TextWrapping="NoWrap"
                                   TextTrimming="CharacterEllipsis" />
                    </Grid>
                </Fluent:RibbonTitleBar.Header>
            </Fluent:RibbonTitleBar>

            <Fluent:RibbonTabControl Menu="{TemplateBinding Menu}"
                                     Style="{DynamicResource RibbonTabControlStyle}"
                                     x:Name="PART_RibbonTabControl"
                                     Focusable="False"
                                     ContextMenu="{Binding ContextMenu, ElementName=PART_LayoutRoot}">
                <Fluent:RibbonTabControl.Margin>
                    <MultiBinding Converter="{x:Static Converters:StaticConverters.ThicknessConverter}">
                        <Binding Source="{x:Static internal:DoubleUtil.Zero}" />
                        <Binding RelativeSource="{RelativeSource Self}"
                                 Path="(Fluent:RibbonProperties.TitleBarHeight)" />
                        <Binding Source="{x:Static internal:DoubleUtil.Zero}" />
                        <Binding Source="{x:Static internal:DoubleUtil.Zero}" />
                    </MultiBinding>
                </Fluent:RibbonTabControl.Margin>                
            </Fluent:RibbonTabControl>
            <Border x:Name="border"
                    Margin="0,-2,0,0"
                    BorderBrush="{DynamicResource QuickAccessToolBarOutterBorderBrush}"
                    BorderThickness="0,1"
                    Grid.Row="1"
                    Height="{Binding Path=(Fluent:RibbonProperties.TitleBarHeight), RelativeSource={RelativeSource Self}}">
                <Border BorderBrush="{DynamicResource QuickAccessToolBarInnerBorderBrush}"
                        BorderThickness="0,1"
                        Background="{DynamicResource QuickAccessToolBarInnerBackgroundBrush}">
                    <ContentControl x:Name="contentControl"
                                    HorizontalAlignment="Left">
                        <Fluent:QuickAccessToolBar x:Name="PART_QuickAccessToolBar"
                                                   Style="{DynamicResource QuickAccessToolbarStyle}"
                                                   ShowAboveRibbon="{Binding ShowQuickAccessToolBarAboveRibbon, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                                   HorizontalAlignment="Left"
                                                   Focusable="False" />
                    </ContentControl>
                </Border>
            </Border>           
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsQuickAccessToolBarVisible"
                     Value="False">
                <Setter Property="Visibility"
                        TargetName="border"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="PART_QuickAccessToolBar"
                        Value="Collapsed" />       
            </Trigger>
            <Trigger Property="IsCollapsed"
                     Value="True">
                <Setter Property="Visibility"
                        TargetName="PART_RibbonTabControl"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="border"
                        Value="Collapsed" />               
            </Trigger>
            <Trigger Property="ShowQuickAccessToolBarAboveRibbon"
                     Value="True">
                <Setter Property="Content"
                        TargetName="contentControl"
                        Value="{x:Null}" />
                <Setter Property="QuickAccessToolBar"
                        TargetName="PART_RibbonTitleBar"
                        Value="{Binding ElementName=PART_QuickAccessToolBar, Mode=OneWay}" />
                <Setter Property="Visibility"
                        TargetName="border"
                        Value="Collapsed" />
                <Setter Property="Margin"
                        TargetName="PART_QuickAccessToolBar"
                        Value="0,2,0,0" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="RibbonStyle"
           TargetType="{x:Type Fluent:Ribbon}">
        <Setter Property="Foreground"
                Value="{DynamicResource DefaultFontBrush}" />
        <Setter Property="Template"
                Value="{DynamicResource RibbonControlTemplate}" />
        <Setter Property="FocusVisualStyle"
                Value="{DynamicResource ControlStyleEmptyFocus}" />
        <Setter Property="VerticalAlignment"
                Value="Top" />
        <Setter Property="IsTabStop"
                Value="False" />
        <Setter Property="Fluent:FrameworkHelper.UseLayoutRounding"
                Value="True" />
    </Style>
</ResourceDictionary>